/*
    Project:        Home Power Control
    File:           HPCLogDevice.h
    Author:         christian@karunamusic.at
    Date:           12.2014
    Description:    Baseclass for sbscribers of logmessages.
 */

#ifndef HPCLOGDEVICE_H
#define HPCLOGDEVICE_H

#include "HPCLogger.h"

/** \brief Baseclass for logdevices.
 * This is the baseclass for devices/targets which handle logmessages
 * (i.e. screen, file, database)
 * It connects/disconnects automatically to/from the loggers logevent.
 */
class HPCLogDevice
{
public:
    /** \brief Constructor
     * Set th loglevel of this target and connect to thelogevent.
     * \param lv The loglevel.
     *
     */
    HPCLogDevice( TLogLevel lv );
    /** \brief Destructor
     * Disconnects from the logevent.
     *
     */
    virtual ~HPCLogDevice();

    /**< Get the loglevel. */
    inline TLogLevel LogLevel() const
        { return m_LogLevel; }
    /**< Set the loglevel. */
    inline HPCLogDevice& LogLevel( TLogLevel lv )
        { m_LogLevel = lv; return *this; }

    /** \brief Callback method for the logmessage.
     * This method is registered to the logevent as callback to recieve the logmessage.
     * This is an abstract method and has to be implemented in derived classes!
     *
     * \param lm the logmessage
     *
     */
    virtual void OnLog( const HPCLogMessage& lm ) = 0;

private:
    TLogLevel m_LogLevel; /**< the loglevel */
    HPCLogger::connection_t m_Event; /**< connection handle to the logevent. */
};

#endif // HPCLOGDEVICE_H
